<?php
/**
 * Created by PhpStorm.
 * User: 24339
 * Date: 2018/10/24
 * Time: 9:52
 */

namespace app\index\controller;
use think\Db;
use think\Controller;

class Area extends Controller
{
    public function lists(){
        $data=Db::table('area')->paginate(5);
        $this->assign('data',$data);
        return view();
    }
    public function add(){
        if(request()->isPost()){
            $save = input('post.');
            $cate = db('area')->insert($save);
            if($cate){
                $this->success('添加分类成功','lists');
            }else{
                $this->error('添加分类失败');
            }
        }
        return view();
    }
    public function edit(){
        if(request()->isPost()) {
            $save = input('post.');
            $area = db('area')->where('id',input('id'))->update($save);
            if($area){
                $this->success('修改分类成功','lists');
            }else{
                $this->error('修改分类失败');
            }
        }
        $id=input('id');
        $admins=db('area')->find($id);
        $this-> assign('admins',$admins);
        return $this->fetch('edit');
        }
        public function del(){
            $del = db('area')->delete(input('id'));
            if($del){
                $this->success('删除区域成功!','lists');
            }
            else{
                $this->error('删除区域失败!');
            }
        }
}